home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Util / C-Cm / Changeling 2.0 / Changeling 1.0.Pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-03-13  |  5.5 KB  |  142 lines  |  [TEXT/PJMM]

  1. (*************************)
  2. (*  Michael Coyle and Neal Tibrewala  *)
  3. (*                                                      *)
  4. (* If you find this code useful, please *)
  5. (* send a postcard to:                        *)
  6. (*      Neal Tibrewala                         *)
  7. (*      P.O. Box 428                            *)
  8. (*      Old Westbury, N.Y. 11568         *)
  9. (*************************)
  10.  
  11. program changeling (input, output);
  12.  
  13. (* Changeling allows a user to change the creator and file types of any file. *)
  14. (* The file selection routine allows for both a dialog box and drag and drop. *)
  15.  
  16.     type
  17.         pointer = ^nodetype;
  18.         nodetype = record
  19.                 info: str255;
  20.                 aux: integer;
  21.                 link: pointer;
  22.             end;
  23.  
  24.     var
  25.         display, who, what: str255;
  26.         deinfo: finfo;
  27.         status: oserr;
  28.         defile: pointer;
  29.  
  30.     procedure selector;
  31. (* Gets files to change by either dialog box or drag 'n drop, puts them on a linked list. *)
  32.         var
  33.             message, count: integer;
  34.         procedure dragndrop;
  35. (* Handles drag 'n drop files with 'getappfiles'. *)
  36.             var
  37.                 cryo: pointer;
  38.                 thefile: appfile;
  39.                 swiper: integer;
  40.         begin
  41.             new(defile);
  42.             getappfiles(1, thefile);     (* Gets the first dragged 'n dropped file. *)
  43.             defile^.info := thefile.fname;     (* Puts the file's name onto the linked list. *)
  44.             defile^.aux := thefile.vrefnum;     (* Puts on the Volume Reference Number. *)
  45.             defile^.link := nil;
  46.             cryo := defile;
  47.             if count > 1 then
  48.                 for swiper := 2 to count do
  49.                     begin
  50.                         new(cryo^.link);
  51.                         cryo := cryo^.link;
  52.                         getappfiles(swiper, thefile);     (* Gets the next few files, up to count. *)
  53.                         cryo^.info := thefile.fname;     (* Puts the file's name onto the linked list. *)
  54.                         cryo^.aux := thefile.vrefnum;     (* Puts on the Volume Reference Number. *)
  55.                         cryo^.link := nil;
  56.                     end;
  57.         end;
  58.         procedure dialogselect;
  59. (* Uses 'sfgetfile' to put up an 'open' dialog box to choose the file. *)
  60.             var
  61.                 dlgorigin: point;
  62.                 zetypelist: sftypelist;
  63.                 rsvp: sfreply;
  64.         begin
  65.             new(defile);
  66.             defile^.link := nil;
  67.             setpt(dlgorigin, 80, 60);     (* Sets the dialog box location to 80, 60*)
  68.             sfgetfile(dlgorigin, '', nil, -1, zetypelist, nil, rsvp);     (* Puts up an 'open' dialog box. *)
  69.             if not rsvp.good then     (* If the cancel button was pressed, good is false. *)
  70.                 halt;
  71.             defile^.info := rsvp.fname;     (* Puts the file's name onto the linked list. *)
  72.             defile^.aux := rsvp.vrefnum;     (* Puts on the Volume Reference Number. *)
  73.         end;
  74.  
  75. (* Main procedure calls 'countappfiles' to see if files were dragged. *)
  76.     begin
  77.         countappfiles(message, count);     (* Counts number of dragged 'n dropped files. *)
  78.         if count = 0 then
  79.             dialogselect     (* Calls up the 'open' dialog box and handles choice. *)
  80.         else
  81.             dragndrop;     (* Handles dragged 'n dropped files. *)
  82.     end;
  83.  
  84.     procedure changer;
  85. (* Takes files from the linked list and allows the user to change the types. *)
  86.         var
  87.             choice, itemtype, loop: integer;
  88.             itemhandle: handle;
  89.             itemrect: rect;
  90.             dedialog: dialogptr;
  91.             done: boolean;
  92.     begin
  93.         while defile <> nil do     (* This will run until the linked list is out of files. *)
  94.             begin
  95.                 done := false;
  96.                 display := defile^.info;
  97.                 status := getfinfo(defile^.info, defile^.aux, deinfo);     (* Gets info about the current file. *)
  98.                 while pos(display, ':') <> 0 do
  99.                     delete(display, 1, pos(display, ':'));
  100.                 paramtext(display, '', '', '');     (* Puts the name of the current file into the next dialog. *)
  101.                 who := deinfo.fdcreator;     (* Assigns the creator type to 'who'. *)
  102.                 what := deinfo.fdtype;     (* Assigns the file type to 'what'. *)
  103.                 dedialog := getnewdialog(1001, nil, windowptr(-1));     (* Loads dialog 1001 into 'dedialog' from rsrc file. *)
  104.                 setport(dedialog);     (* Makes 'dedialog' active. *)
  105.                 showwindow(dedialog);     (* Shows 'dedialog'. *)
  106.                 getditem(dedialog, 4, itemtype, itemhandle, itemrect);     (* Makes dialog item 4 ready to accept data. *)
  107.                 setitext(itemhandle, deinfo.fdcreator);     (* Puts the creator type into item 4. *)
  108.                 getditem(dedialog, 6, itemtype, itemhandle, itemrect);     (* Makes dialog item 6 ready to accept data. *)
  109.                 setitext(itemhandle, deinfo.fdtype);     (* Puts the file type into item 6. *)
  110.                 while not done do     (* Checks if user has pressed the 'OK' button. *)
  111.                     begin
  112.                         modaldialog(nil, choice);     (* Finds out what item the user clicked on. *)
  113.                         case choice of     (* Handles the user's choice. *)
  114.                             1: 
  115.                                 done := true;
  116.                             4, 6: 
  117.                                 begin
  118.                                     getditem(dedialog, choice, itemtype, itemhandle, itemrect);     (* Makes the selected item ready to accept data. *)
  119.                                     if choice = 4 then
  120.                                         getitext(itemhandle, who)     (* Puts what the user typed into 'who'. *)
  121.                                     else
  122.                                         getitext(itemhandle, what);     (* Puts what the user typed into 'what'. *)
  123.                                 end;
  124.                             7: 
  125.                                 halt;
  126.                         end;
  127.                     end;
  128.                 deinfo.fdcreator := copy(who, 1, 4);     (* Assigns the user's creator type to the info record. *)
  129.                 deinfo.fdtype := copy(what, 1, 4);      (* Assigns the user's file type to the info record. *)
  130.                 hidewindow(dedialog);     (* Hides 'dedialog'. *)
  131.                 disposewindow(dedialog);     (* Dumps 'dedialog' from memory. *)
  132.                 if status = noerr then     (* If there is no operating system error, the new info is saved. *)
  133.                     status := setfinfo(defile^.info, defile^.aux, deinfo);
  134.                 defile := defile^.link;
  135.             end;
  136.     end;
  137.  
  138. begin
  139.     setcursor(arrow);     (* Sets the mouse cursor to an arrow. *)
  140.     selector;     (* Selects the files to change. *)
  141.     changer;     (* Allows user to input changes into a dialog box. *)
  142. end.